package ahu.zdw.com;

import java.util.Arrays;

/**
 * Author: Zhang Dongwei
 * Date: 2021/12/13 21:27
 */
public class _1_TwoSum {
    public static void main(String[] args) {
//        Solution solution = new _1_TwoSum().new Solution(); 如果Solution只用class修饰，如果加上static即可直接引用
        Solution solution = new Solution();
        int[] a={1, 2, 3, 4};
        int[] ints = solution.twoSum(a,5);
        System.out.println(ints); //输出为类
        System.out.println(ints.getClass().toString());
        System.out.println(Arrays.toString(ints));

//        int[] a1 = [1, 2, 3, 4];  中括号错，要大括号
//        int[] ans1 = solution.twoSum({2, 4, 1, 5}, 6); 要提前定义，然后再传入
    }
    static class Solution {
        public int[] twoSum(int[] nums, int target) {
            int l = nums.length;
            int[] ans = new int[2];
            int i,j;
            for(i=0;i<l-1;i++){
                for(j=i+1;j<l;j++){
                    if(nums[i]+nums[j] == target){
                        ans[0] = i;
                        ans[1] = j;
                    }
                }
            }
            return ans;
        }
    }
}